package com.jsh.erp.service.bank;

import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.IdUtils;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service(value = "bank_component")
@BankResource
public class BankComponent implements ICommonQuery {

    @Resource
    private BankService bankService;

    @Override
    public Object selectOne(String id) throws Exception {
        return bankService.getBank(id);
    }

    @Override
    public List<?> select(Map<String, String> map)throws Exception {
        return getBankList(map);
    }

    private List<?> getBankList(Map<String, String> map) throws Exception{
        String search = map.get(Constants.SEARCH);
        String name = StringUtil.getInfo(search, "bankName");
        return bankService.select(name, QueryUtils.offset(map), QueryUtils.rows(map));
    }

    @Override
    public Long counts(Map<String, String> map) throws Exception{
        String search = map.get(Constants.SEARCH);
        String name = StringUtil.getInfo(search, "bankName");
        return bankService.countBank(name);
    }

      @Override
    public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
        obj.put("id", IdUtils.getUUID());

        return bankService.insertBank(obj, request);
    }

    @Override
    public int update(JSONObject obj, HttpServletRequest request)throws Exception {
        return bankService.updateBank(obj, request);
    }

    @Override
    public int delete(String id, HttpServletRequest request)throws Exception {
        return bankService.deleteBank(id, request);
    }

    @Override
    public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
        return bankService.batchDeleteBank(ids, request);
    }

    @Override
     public int checkIsNameExist(String id, String name) throws Exception{
        return bankService.checkIsNameExist(id, name);
    }

}
